from django.conf.urls.defaults import *
from django.views.static import serve
from django.conf import settings
from django.contrib import admin

from reps.interns.helpers import render_template

admin.autodiscover()

reps_views = 'reps.interns.views.'
reps_reports = 'reps.interns.reports.'

urlpatterns = patterns('',
    (r'^$', render_template, {'template': 'home.html'}),
    (r'^contact/$', render_template, {'template': 'contact.html'}),
    (r'^forbidden/$', render_template, {'template': 'forbidden.html'}),

    # Account operations
    (r'^accounts/login/$', 'django.contrib.auth.views.login'),
    (r'^accounts/logout/$', reps_views + 'logout_view'),
    (r'^accounts/profile/$', reps_views + 'profile'),
    (r'^accounts/register/((?P<spec_id>\d+)/)?$', reps_views + 'register'),
    (r'^accounts/reset_password/$', reps_views + 'reset_password'),
    (r'^accounts/change_details/((?P<which>password|email)/)?$',
     reps_views + 'change_details'),
    
    # Specialization selection
    (r'^specialization/select/(?P<spec_id>\d+)/$',
     reps_views + 'select_specialization'),
    (r'^specialization/select/(?P<all>all)/$',
     reps_views + 'select_specialization'),

    # Students CRUD
    (r'^students/$', reps_views + 'list_students'),
    (r'^students/import/((?P<save>save)/)?$', reps_views + 'import_students'),
    (r'^students/new/$', reps_views + 'new_student'),
    (r'^students/list/$', reps_views + 'list_students'),
    (r'^students/show/(?P<student_id>\d+)/$', reps_views + 'show_student'),
    (r'^students/edit/(?P<student_id>\d+)/$', reps_views + 'edit_student'),
    (r'^students/(?P<undelete>un)?delete/(?P<student_id>\d+)/$',
     reps_views + 'delete_student'),

    # Companies CRUD
    (r'^companies/$', reps_views + 'list_companies'),
    (r'^companies/my/$', reps_views + 'my_companies'),
    (r'^companies/new/((?P<main_branch_id>\d+)/)?$', reps_views + 'new_company'),
    (r'^companies/list/((?P<main_branch_id>\d+)/)?$', reps_views + 'list_companies'),
    (r'^companies/show/(?P<branch_id>\d+)/$', reps_views + 'show_company'),
    (r'^companies/edit/(?P<branch_id>\d+)/$', reps_views + 'edit_company'),
    (r'^companies/seize/all/$', reps_views + 'seize_all_seizable_companies'),
    (r'^companies/seize/(?P<branch_id>\d+)/$', reps_views + 'seize_company'),

    # Training dates CRUD
    (r'^dates/$', reps_views + 'list_dates'),
    (r'^dates/generate/$', reps_views + 'generate_dates'),
    (r'^dates/list/$', reps_views + 'list_dates'),
    (r'^dates/edit/(?P<td_id>\d+)/$', reps_views + 'edit_date'),
    (r'^dates/delete/(?P<td_id>\d+)/$', reps_views + 'delete_date'),
    (r'^dates/new/(?P<spec_id>\d+)/$', reps_views + 'new_date'),
    
    # Archive CRUD
    (r'^archive/$', reps_views + 'list_archive'),
    (r'^archive/recover/(?P<training_id>\d+)/$', reps_views + 'list_archive'),
    (r'^archive/list/$', reps_views + 'list_archive'),
    (r'^archive/list/(?P<year_no>\d+)/$', reps_views + 'list_archive'),
    (r'^archive/list/recover/(?P<training_id>\d+)/$', reps_views + 'list_archive'),
    (r'^archive/list/(?P<year_no>\d+)/recover/(?P<training_id>\d+)/$', reps_views + 'list_archive'),
    

    # Trainings CRUD
    (r'^trainings/$', reps_views + 'list_trainings'),
    (r'^trainings/lock_all/$', reps_views + 'bulk_lock_trainings'),
    (r'^trainings/unlock_all/$', reps_views + 'bulk_lock_trainings', {'unlock_all' : True}),
    (r'^trainings/switch_all/$', reps_views + 'bulk_lock_trainings', {'switch_all' : True}),
    (r'^trainings/new/(?P<student_id>\d+)/$', reps_views + 'new_training'),
    (r'^trainings/list/$', reps_views + 'list_trainings'),
    (r'^trainings/(?P<unlock>un)?lock/(?P<training_id>\d+)/$',
     reps_views + 'lock_training'),
    (r'^trainings/edit/(?P<training_id>\d+)/$', reps_views
                                                + 'edit_student_training'),
    (r'^trainings/mark/(?P<training_id>\d+)/$', reps_views + 'mark_training'),
    (r'^trainings/show/(?P<training_id>\d+)/$', reps_views
                                                + 'show_student_training'),

    (r'^settings/$', reps_views + 'edit_settings'),

    # Reports
    (r'^reports/$', reps_reports + 'reports'),
    (r'^reports/passed/$', reps_reports + 'show_pass_report'),
    (r'^reports/failed/$', reps_reports + 'show_fail_report'),
    (r'^reports/hostels/$', reps_reports + 'show_hostel_report'),
    (r'^reports/refunds/$', reps_reports + 'show_refund_report'),
    (r'^reports/contracts/$', reps_reports + 'generate_contracts'),
    (r'^reports/blankcontract/$', reps_reports + 'generate_in_blanco_contract'),

    # Admin interface
    (r'^admin/jsi18n', 'django.views.i18n.javascript_catalog'),
    (r'^admin/(.*)', admin.site.root),

    # Student interface
    (r'^my_trainings/$', reps_views + 'student_trainings'),
    (r'^my_trainings/show/(?P<training_id>\d+)/$', reps_views
                                                   + 'show_student_training'),
    (r'^my_trainings/edit/(?P<training_id>\d+)/$', reps_views
                                                   + 'edit_student_training'),

    # Static serve, for media files (it will hopefully be removed in
    # working system)
    (r'^(images/.*)$', serve, {'document_root': settings.PROJECT_HOME + 'media'}),
    (r'^(css/.*\.css)$', serve, {'document_root': settings.PROJECT_HOME + 'media'}),
    (r'^(src/dropdown.js)$', serve, {'document_root': settings.PROJECT_HOME + 'media'}),
    
    # Debug
    (r'^test/$', reps_views + 'test'),
)

